import {
  wxRequest
} from '../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()

Page({
  data: {
    imgUrl: app.globalData.imgUrl,
    list: [],
    pageNo: 1,
    keyword: '',
  },

  onShow: function() {
    this.getList()
  },


  //推荐活动/资讯
  getList: function() {
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/sys/protected/info/list',
      method: 'POST',
      data: {
        cityId: wx.getStorageSync('loacaltionCity').code || '',
        keyword: this.data.keyword
      }
    }, (res) => {
      let list = res.list;
      if (list.length > 0) {
        if (this.data.pageNo !== 1) {
          list = this.data.list.concat(list);
        }
        list.map(item => {
          item.modifyDateText = item.modifyDate.substring(0, 10)
        })
        this.setData({
          list: list,
          pageNo: res.page.pageNo,
          hasNextPage: res.page.hasNextPage,
        });
      }
    }) 

  },


  //下拉刷新
  onPullDownRefresh: function() {
    this.refreshData();
    wx.stopPullDownRefresh()
  },

  refreshData: function() {
    this.setData({
      pageNo: 1
    })
    this.getList();
  },

  toArticle: function(e) {
    var id = e.currentTarget.dataset.id;

    console.log(id, 'id')
    wx.navigateTo({
      url: '/pages/activity/detail?id=' + id,
    })
  },

  //搜索关键词
  seachInputConfirm: function(e) {
    this.setData({
      pageNo: 1,
      keyword: e.detail.value
    })
    this.getList();
  },
  
  seachBtn: function () {
    this.setData({
      pageNo: 1,
      keyword: this.data.keyword
    })
    this.getlist();
  },


  seachInputVal: function(e) {
    var inputval = e.detail.value;
    console.log(e)
    this.setData({
      keyword: inputval
    })
  },

  //清空
  clearInput: function() {
    this.setData({
      keyword: ''
    })
    this.getList();
  },



  //分享
  onShareAppMessage: function() {

  }

})